package com.bop.dehong.decaifu.fragment;

import android.app.Activity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;

import com.base.dehong.http.RequestCallBack;
import com.bop.dehong.R;
import com.bop.dehong.base.BaseFragment;
import com.bop.dehong.config.Config;
import com.bop.dehong.decaifu.DeCaifuActivity;
import com.bop.dehong.info.entity.InfoItemEntity;
import com.bop.dehong.info.entity.ToubiaoBasicInfoEntity;
import com.bop.dehong.http.model.ToubiaoInfoModel;
import com.bop.dehong.widget.RoundProgressBar;

public class BasicInfo extends BaseFragment {
	private TextView basicinfo_title, basicinfo_rate, basicinfo_totalbid, basicinfo_avalible;
	private TextView basicinfo_deadline, basicinfo_paybackway, basicinfo_calculatetime, basicinfo_paybacktime;
	private RoundProgressBar toubiao_percent_roundprobar;
	private String id;
	private ToubiaoInfoModel toubiaoInfoModel;
	private DeCaifuActivity mDeCaifuActivity;
	private InfoItemEntity entity;
	
	@Override
	protected void initTop() {
		mPageName = getClass().getName();
	}

	@Override
	public void onResume()
	{
		if (mDeCaifuActivity.isFristStart()) {
			initData();
			mDeCaifuActivity.setFristStart(false);
		}
		super.onResume();
	}
	
	@Override
	protected void initUI() {
		basicinfo_title = getView(R.id.basicinfo_title);
		basicinfo_rate = getView(R.id.basicinfo_rate);
		basicinfo_totalbid = getView(R.id.basicinfo_totalbid);
		basicinfo_avalible = getView(R.id.basicinfo_avalible);
		basicinfo_deadline = getView(R.id.basicinfo_deadline);
		basicinfo_paybackway = getView(R.id.basicinfo_paybackway);
		basicinfo_calculatetime = getView(R.id.basicinfo_calculatetime);
		basicinfo_paybacktime = getView(R.id.basicinfo_paybacktime);
		toubiao_percent_roundprobar = getView(R.id.toubiao_percent_roundprobar);
		id = getActivity().getIntent().getExtras().getString(Config.CAT_ID);
	}

	@Override
	public void initData() {
		if (entity != null) {
			basicinfo_title.setText(entity.getTitle());
			basicinfo_rate.setText(entity.getRates());
			toubiao_percent_roundprobar.setTitleName(entity.getState_name());
			toubiao_percent_roundprobar.setProgress(entity.getPercent());
			basicinfo_totalbid.setText(entity.getMoney());
			basicinfo_avalible.setText(entity.getSurplus());
			basicinfo_deadline.setText(entity.getDeadlines());
			basicinfo_paybackway.setText(entity.getWaytype());
			basicinfo_calculatetime.setText(entity.getReviewtime());
			basicinfo_paybacktime.setText(entity.getLimittime());
		}else {
			showProgressDialog();
			if (toubiaoInfoModel == null) {
				toubiaoInfoModel = new ToubiaoInfoModel(getActivity(), callback);
			}
			toubiaoInfoModel.doNet(id);
		}
	}

	RequestCallBack<ToubiaoBasicInfoEntity> callback = new RequestCallBack<ToubiaoBasicInfoEntity>() {

		@Override
		public void end() {
			disappearProgressDialog();
		}
		
		public void onSuccess(ToubiaoBasicInfoEntity info) {
			entity = info.getItem();
			basicinfo_title.setText(entity.getTitle());
			basicinfo_rate.setText(entity.getRates());
			toubiao_percent_roundprobar.setTitleName(entity.getState_name());
			toubiao_percent_roundprobar.setProgress(entity.getPercent());
			basicinfo_totalbid.setText(entity.getMoney());
			basicinfo_avalible.setText(entity.getSurplus());
			basicinfo_deadline.setText(entity.getDeadlines());
			basicinfo_paybackway.setText(entity.getWaytype());
			basicinfo_calculatetime.setText(entity.getReviewtime());
			basicinfo_paybacktime.setText(entity.getLimittime());
			super.onSuccess(info);
		};
		
	};
	
	
	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		mDeCaifuActivity = (DeCaifuActivity) activity;
	}	
	
	@Override
	protected int getContentViewId() {
		return R.layout.fragment_basicinfo;
	}

	@Override
	public void onClick(View v)
	{
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id)
	{
		// TODO Auto-generated method stub
		
	}

}
